﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Utilities.QuickSql;
using MySql.Data;

namespace Deviseur_Cs2i_Car
{
    public partial class AdminVoiOption : Form
    {
        public AdminVoiOption()
        {
            InitializeComponent();

            Thread VoiOptionThread = new Thread(new ThreadStart(getAllVoiOption_Thread));
            VoiOptionThread.Start();
        }
        private void getAllVoiOption_Thread()
        {
            Invoke(new MethodInvoker(getAllVoiOption));
        }
        private void getAllVoiOption()
        {
            Table VoiOptionVoiture = Program.Db.QueryTable("SELECT V.NomVoi, C.LibelleCateg, O.LibelleOption, S.NomSSOption, V.NumVoi, O.NumOption FROM VOITURE V INNER JOIN Voi_Option VO ON VO.NumVoi = V.NumVoi LEFT OUTER JOIN OPTIONS O ON VO.NumOption = O.NumOption LEFT OUTER JOIN CATEGOPTION C ON C.NumCateg = O.NumCateg LEFT OUTER JOIN SSOPTION S ON S.NumOption = O.NumOption ORDER BY 1 ASC");

            this.dataVoiOption.Rows.Clear();

            foreach (Record r in VoiOptionVoiture)
                this.dataVoiOption.Rows.Add(r.Values[0], r.Values[1], r.Values[2], r.Values[3], r.Values[4], r.Values[5]);
        }

        private void buttonAddVoiOption_Click(object sender, EventArgs e)
        {
            AddVoiOption FenAddVoiOption = new AddVoiOption();
            FenAddVoiOption.ShowDialog();
        }
        private void buttonUpdateVoiOption_Click(object sender, EventArgs e)
        {
            AddVoiOption FenAddVoiMotor = new AddVoiOption(Convert.ToInt32(this.dataVoiOption.SelectedRows[0].Cells[4].Value.ToString()), Convert.ToDouble(this.dataVoiOption.SelectedRows[0].Cells[5].Value.ToString()));
            FenAddVoiMotor.ShowDialog();
        }
        private void buttonDelVoiOption_Click(object sender, EventArgs e)
        {
            VoiOption delVoiOption = new VoiOption();
            delVoiOption.delete_VoiOption(Convert.ToInt32(this.dataVoiOption.SelectedRows[0].Cells[4].Value.ToString()), Convert.ToDouble(this.dataVoiOption.SelectedRows[0].Cells[5].Value.ToString()));
            Thread VoiMotorThread = new Thread(new ThreadStart(getAllVoiOption_Thread));
            VoiMotorThread.Start();
        }
    }
}
